﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Data;
using System.Drawing;
using System.Configuration;
using System.Data;

namespace Presentation.Controls
{
    public partial class galeriaimagen : System.Web.UI.UserControl
    {
        public List<Imagen> lisImagen { get; set; }
        public List<Imagen> lisImagenZoom { get; set; }
        public int ImagenesPorFila { get; set; }
        public int Height { get; set; }
        

        public galeriaimagen()
        {
            lisImagen = new List<Imagen>();
            lisImagenZoom = new List<Imagen>();
        }

        protected override void  OnInit(EventArgs e)
        {

            imagenzoom[] arreglo;
            arreglo = new imagenzoom[lisImagen.Count];
            int nroImagen = 0;
            foreach (Data.Imagen i in lisImagen)
            {
                System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
                img.ImageUrl = ConfigurationManager.AppSettings["ImagesUploadPath"] + i.ruta;
                img.AlternateText = i.alt;
                img.Height = Height;
                img.BorderWidth = 2;
                img.BorderStyle = BorderStyle.Outset;
                img.BorderColor = Color.Transparent;
                Presentation.Controls.imagenzoom imagenzoom1 = (Presentation.Controls.imagenzoom)LoadControl("~/controls/imagenzoom.ascx");
                imagenzoom1.ImageUrl = img.ImageUrl;
                imagenzoom1.ImageTitle = img.AlternateText;
                imagenzoom1.Height = 150;
                imagenzoom1.Width = 150;
                arreglo[nroImagen] = imagenzoom1;
                nroImagen++;
       
            }

            fillImagePanel(arreglo);
                
 	        base.OnInit(e);
        }

        private void fillImagePanel(imagenzoom[] arreglo)
        {
            int index = 0;
            int cantFil = 2;
            int col = 0;
            int indexCol = 0;
            for (int fil = 0; fil < cantFil; fil++)
            {
                TableRow r = new TableRow();

                while ((col < 4) && (index < arreglo.Count()))
                {
                    TableCell c = new TableCell();
                    c.Controls.Add(arreglo[index]);
                    r.Cells.Add(c);
                    tblImg.Rows.Add(r);
                    index++;
                    indexCol++;
                    col++;
                }
                col = 0;
                index = indexCol;
                tblImg.Rows.Add(r);
            }
            ImagePanel.Controls.Add(tblImg);
        }        

        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}